//
//  TXFStatuesThreeView.swift
//  weibo飞飞
//
//  Created by 田侠飞 on 16/6/29.
//  Copyright © 2016年 田侠飞. All rights reserved.
//

import UIKit
import SnapKit
class TXFStatuesThreeView: UIView {
    
    var pictureViewContraint : Constraint?
    var status : TXFStatues? {
        
        didSet{
            
            contentLab.text = status?.retweeted_status?.text
            contentLab.attributedText = status?.retweeted_status?.textAttr
            pictureViewContraint?.uninstall()
            if status?.retweeted_status?.pic_urls?.count > 0{
            
            //有图片:
                //显示:
                
                pictureView.hidden = false
                
                //赋值:
                pictureView.pictureInfo = status?.retweeted_status?.pic_urls
                
//                pictureView.p
                self.snp_makeConstraints { (make) -> Void in
                    
                    pictureViewContraint  = make.bottom.equalTo(pictureView).offset(10).constraint
                    
                    
                }
            
            }else{
            //没图片:
            
                pictureView.hidden = true
                self.snp_makeConstraints { (make) -> Void in
                    
                    pictureViewContraint  = make.bottom.equalTo(contentLab).offset(10).constraint
                    
                    
                }
            }
            
        }
        
        
    }
    
    
    
    
   override init(frame: CGRect) {
        super.init(frame: frame)
    
    setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    func setupUI(){

    addSubview(contentLab)
    addSubview(pictureView)
    contentLab.snp_makeConstraints { (make) -> Void in
        
        
        make.top.equalTo(self).offset(10)
        
        make.left.equalTo(self).offset(10)
        }
        
     
    pictureView.snp_makeConstraints { (make) -> Void in
        
        make.size.equalTo(CGSizeMake(100, 100))
        
        
        make.left.equalTo(contentLab)
        
        make.top.equalTo(contentLab.snp_bottom).offset(10)
        }
    self.snp_makeConstraints { (make) -> Void in
        
     pictureViewContraint  = make.bottom.equalTo(pictureView).offset(10).constraint
        
        
        }
    
    }
    
    //创建控件:
    private lazy var contentLab: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWith: SCREENW-20)
    
    private lazy var pictureView: TXFPictureView = TXFPictureView()
    
    

}
